import java.util.Stack;

/**
 * 用栈实现队列
 */
public class MyQueue {
    Stack<Integer> stack1;
    Stack<Integer> stack2;
    public MyQueue() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }
    
    public void push(int x) {
        stack1.push(x);
    }
    
    public int pop() {
        if (empty()) {
            return -1;
        }
        if (stack2.isEmpty()) {
            int size = stack1.size();
            while (size > 0) {
                stack2.push(stack1.pop());
                size--;
            }
        }
        return stack2.pop();
    }
    
    public int peek() {
        if (empty()) {
            return -1;
        }
        if (stack2.isEmpty()) {
            int size = stack1.size();
            while (size > 0) {
                stack2.push(stack1.pop());
                size--;
            }
        }
        return stack2.peek();
    }
    
    public boolean empty() {
        if (stack1.isEmpty() && stack2.isEmpty()) {
            return true;
        }
        return false;
    }
}

class Test {
    public static void main(String[] args) {
        MyQueue myQueue = new MyQueue();
        myQueue.push(1); // queue is: [1]
        //myQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)
        //System.out.println(myQueue.peek());
        System.out.println(myQueue.pop());
        System.out.println(myQueue.empty());

    }
}